﻿using Service.src.Model.Folw;
using Service.src.NW.Enum;
using Service.src.NW.Model;
using Service.src.NW.Model.Enum;
using Service.src.NW.Model.Folw;


namespace Service.src.NW.Processor.Core.Device.SerialPort
{
    internal class SerialPortProcessor : BaseProcessor
    {

        internal static void Run(NodeProcessor nodeProcessor, NodeInputParam Input)
        {
            NodeStatusEnum Status = NodeStatusEnum.ERROR;
            if (Input?.CommonInput?.DataSourceId > 0 && AppData.ModbusServices.ContainsKey(Input.CommonInput.DataSourceId))
            {
                string ReceivedData = AppData.ModbusServices[Input.CommonInput.DataSourceId].DataString;
                SetNodeOutParamValue(nodeProcessor, NodeOutParamNameEnum.DEVICE_READ_RESULT, ReceivedData);
                Status = NodeStatusEnum.SUCCESS;
            }
            else {
                SendNodeLoggerError(nodeProcessor,$"串口节点执行失败，原因：节点未选择串口设备，或者串口连接失败");
            }
         
            Complete(nodeProcessor, Status);
        }
    }
}
